package com.jack.online.study.config.mvc;

import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {


    @Resource
    private LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(loginInterceptor).addPathPatterns("/api/**/auth/**");
        registry.addInterceptor(loginInterceptor).addPathPatterns("/api/trade/order/auth/is-buy/**");
        registry.addInterceptor(loginInterceptor).addPathPatterns("/api/edu/course-collect/auth/is-collect/**");
        registry.addInterceptor(loginInterceptor).addPathPatterns("/api/trade/order/auth/save/**");
    }

//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        //项目中的所有接口都支持跨域
//        registry.addMapping("/**")
//                //所有地址都可以访问，也可以配置具体地址
////                .allowedOrigins("*")
//                .allowedOriginPatterns("*")
//                //允许的请求方式
//                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
//                // 允许的请求头
//                .allowedHeaders("*")
//                //是否支持跨域Cookie
//                .allowCredentials(true)
//                // 跨域允许时间
//                .maxAge(3600);
//    }

}
